#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[1005],n,ans,m;string s,x,y;
const int mod=1e9+7;
map<string,int>mp;
void dfs(int p,int n,int k,int op){
	if(p>n){
		if(k!=m&&k+1!=m) return;
		for(int i=1;i<=n;i++){
			if(a[i]>y[i]-'0')return;
			if(y[i]-'0'>a[i]) break;
		}
		for(int i=1;i<=n;i++){
			if(a[i]<x[i]-'0')return;
			if(x[i]-'0'<a[i]) break;
		}
		string t;
		for(int i=1;i<=n;i++){t+=char(a[i]+'0');}
		if(mp[t]) return;mp[t]=1;
		int num=1;
		for(int i=n;i;i--){
			ans=(ans+num*a[i]%mod)%mod;num=(num*2)%mod;
		}
		return;
	}
	int xb=s[p-1];
	if(op==1) xb=1-xb;
	a[p]=xb;
	dfs(p+1,n,k,op);
	op=1-op;xb=1-xb;
	a[p]=xb;
	dfs(p+1,n,k+1,op);
}
signed main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;cin>>s>>x>>y;
	s=' '+s,x=' '+x,y=' '+y;
	for(int i=1;i<n;i++){
		if(s[i]=='L') s[i]=0;
		else s[i]=1;
	}
	a[1]=1;
	dfs(2,n,0,0);
	
	dfs(2,n,0,1);
	cout<<ans;
	return 0;
}
